﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.controllers.collections {
    import net.wooga.pets.events.*;
    import net.wooga.pets.models.world.vos.*;
    import net.wooga.pets.models.vo.*;
    import net.wooga.pets.models.*;
    import net.wooga.pets.constants.*;
    import org.robotlegs.mvcs.*;

    public class UpdateCollectionPopupsCommand extends Command {

        public var event:InfoEvent;
        public var collactableModel:CollectableModel;

        override public function execute():void{
            var _local1:RewardItemVO = (this.event.info as RewardItemVO);
            var _local2:String = _local1.petType;
            var _local3:int = this.getIndex(_local1.itemType);
            var _local4:CollectableVO = this.collactableModel.getCollectableByType(_local2);
            this.checkForCompletion(_local4);
            dispatch(new InfoEvent(EventConstants.UPDATE_COLLECTION_STATUS, _local2, {collectable:_local4, updatedIndex:_local3}));
        }
        private function getIndex(_arg1:String):int{
            var _local2:String = _arg1.slice((_arg1.length - 1), _arg1.length);
            if (((((!((_local2 == "1"))) && (!((_local2 == "2"))))) && (!((_local2 == "3"))))){
                _local2 = "4";
            };
            var _local3:int = (int(_local2) - 1);
            return (_local3);
        }
        private function checkForCompletion(_arg1:CollectableVO):void{
            if (this.collactableModel.completedCollections.hasOwnProperty(_arg1.type)){
                return;
            };
            var _local2:int;
            while (_local2 < (_arg1.requires.length - 1)) {
                if (_arg1.collected[_local2] < _arg1.requires[_local2]){
                    return;
                };
                _local2++;
            };
            var _local3:int = this.collactableModel.collectableMatrix[_arg1.rewardPet];
            if (_local3 < _arg1.requires[3]){
                return;
            };
            this.collactableModel.completedCollections[_arg1.type] = true;
            dispatch(new InfoEvent(EventConstants.CREATE_POPUP, GameConstants.COLLECTION_COMPLETE_POPUP, _arg1.type));
        }

    }
}//package net.wooga.pets.controllers.collections 
